//
//  ViewController.m
//  TFDT
//
//  Created by admin on 2018/4/22.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "ViewController.h"

#import "Masonry.h"

#import "TFDTTableViewCell.h"

#import "UITableView+FDTemplateLayoutCell.h"


@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong)UITableView *table;

@property (nonatomic, strong)NSMutableArray *dataArr;


@end

@implementation ViewController

-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSMutableArray new];
        [_dataArr addObject:@{@"title":@"多哈就是肯定会尽快撒谎的话就撒开的好借口撒的话",@"detail":@"华东科技啊时间快点好好的借口撒的话空间啊说的话就撒的好快好借口撒的话就卡上的"}];
        [_dataArr addObject:@{@"title":@"多哈就是肯定会尽快撒谎的话就撒开的好借口撒的话大时代看了几啊都是零零落落扩大进口零食打卡老师的借口拉萨",@"detail":@"华东科技啊时间快点好好的借口撒的话空间啊说的话就撒的好快好借口撒的话就卡上的姐弟恋卡觉得快拉上就打开了圣诞节卡洛斯点击觉得卡拉斯京的卡洛斯觉得撒开的借口拉萨的借口啦速度的就是克拉的借口拉萨多久啊哭了"}];
    }
    return _dataArr;
}

-(UITableView *)table{
    if (!_table) {
        _table = [UITableView new];
        _table.delegate = self;
        _table.dataSource = self;
        [self.view addSubview:_table];
        [_table registerClass:[TFDTTableViewCell class] forCellReuseIdentifier:@"cell"];
        [_table mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view);
            make.top.equalTo(self.view);
            make.right.equalTo(self.view);
            make.bottom.equalTo(self.view);
            
        }];
    }
    return _table;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self table];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [self.table fd_heightForCellWithIdentifier:@"cell" cacheByKey:indexPath configuration:^(TFDTTableViewCell *cell) {
        
        cell.dic = self.dataArr[indexPath.row];
        
    }];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TFDTTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    [self configureCell:cell atIndexPath:indexPath];
    return cell;
}

- (void)configureCell:(TFDTTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
    //使用Masonry进行布局的话，这里要设置为NO
    cell.fd_enforceFrameLayout = NO;
    cell.dic = self.dataArr[indexPath.row];
}

//移除缓存
- (void)removeVache:(NSIndexPath *)index{
    // 移除 key 对应的高度缓存
    
    [self.table.fd_keyedHeightCache invalidateHeightForKey:index];
    
    // 移除所有高度缓存
    
    [self.table.fd_keyedHeightCache invalidateAllHeightCache];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
